package com.heima.juc.n4.deadlock;

import com.heima.juc.n2.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @author : leimingchao
 * @date Date : 2022年02月11日 20:38
 */
@Slf4j(topic = "c.TestDeadLock")
public class TestDeadLock {

    public static void main(String[] args) {
        Object a = new Object();
        Object b = new Object();

        Thread t1 = new Thread(() ->{
            synchronized (a) {
                log.debug("lock a");
                Sleeper.sleep(1);

                synchronized (b) {
                    log.debug("lock b");
                    log.debug("操作。。。。");
                }
            }
        },"t1");

        Thread t2 = new Thread(() ->{
            synchronized (b) {
                log.debug("lock b");
                Sleeper.sleep(0.5);

                synchronized (a) {
                    log.debug("lock a");
                    log.debug("操作。。。。");
                }
            }
        },"t2");

        t1.start();
        t2.start();
    }
}
